package com.td.framework.webmanager.bmxx.action;

import java.util.List;

import com.td.framework.common.AbstractAction;
import com.td.framework.common.Constant;
import com.td.framework.webmanager.bmxx.service.BmxxService;
import com.td.framework.webmanager.domain.AppsysBmxx;
import com.td.framework.webmanager.page.PageService;
import com.td.framework.webmanager.xtbm.service.XtbmService;
import com.opensymphony.xwork2.Action;

/**
 * 
 * Title:部门信息处理Action Description:处理部门信息 
 * Copyright: Copyright (c) 2008 Company
 * xx公司
 * 
* @author zjp
 * @version 1.0
 */
public class BmxxAction extends AbstractAction implements Action {
	private static final long serialVersionUID = 4010443634262151907L;
	private String target = "";// 返回参数;
	private BmxxService bmxxService = null;// 部门信息业务处理
	private XtbmService xtbmService = null;//系统编码业务层接口;
	private List<AppsysBmxx> bmxxList = null;// 部门信息集合
	private List<AppsysBmxx> treeList = null;// 组织结构树集合
	private String sjbmbh = "";// 上级部门编号
	private String bmbhs = "";// 多个部门编号,中间以","隔开
	private String bmbh = "";//部门编号
	private String sjbmmc = "";//上级部门名称;
	private String urlFlag = "";// 判断查询路径
	private AppsysBmxx appsysBmxx;// 部门信息对象
	private String[] bmId = null;//部门id;
	private String[] pxh = null; //排序号;
	/**
	 * toDo:部门信息列表;
	 * 
	 * @return target;
	 */
	public String listBmxx() {
		int rows = bmxxService.getRows(sjbmbh, appsysBmxx,this.getUserInfo().getYhbh(),
				this.getUserInfo().getBmbh(),Constant.SYS_XTBM);
		page = PageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		bmxxList = bmxxService.findBySjbmbh(sjbmbh, appsysBmxx,this.getUserInfo().getYhbh(),
				this.getUserInfo().getBmbh(),Constant.SYS_XTBM,page.getPageSize(), page.getStartRow());
		if(sjbmbh.equals("-1"))
		{
			//sjbmbh="01";
			this.handleMessage("orderFlag", "-1");
		}
		target = "bmxxList";
		return target;
	}
	/**
	 * @toDo:查询单个部门信息
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String infoBmxx()
	{
		appsysBmxx = bmxxService.getBmxx(bmbh);
		sjbmmc = bmxxService.getBmxx(appsysBmxx.getSjbmbh()).getBmmc();
		target = "info";
		return target;
	}
	/**
	 * toDo:生成部门结构树;
	 * 
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listBmxxTree() {
//		treeList = bmxxService.getTreeList();
		treeList = bmxxService.findBmxxByYhbh(this.getUserInfo().getYhbh(),this.getUserInfo().getBmbh(), 1, Constant.SYS_XTBM, 1);		
		target = "bmxxTree";
		if(this.getRequest().getParameter("selMutiDept")!=null){
			target = "selMutiDept";
		}
		return target;
	}
	/**
	 * toDo:待排序部门列表;
	 * 
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listOrderBmxx()
	{
		bmxxList=bmxxService.findBySjbmbh(sjbmbh);
		target = "orderList";
		return target;
	}
	/**
	 * toDo:生成部门信息添加表单
	 * 
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String createBmxxForm() {
		treeList = bmxxService.getTreeList();
		if(sjbmbh.equals("-1"))
		{
			sjbmbh = "01";
		}
		sjbmmc = bmxxService.getBmxx(sjbmbh).getBmmc();
		appsysBmxx = new AppsysBmxx();
		appsysBmxx.setSjbmbh(sjbmbh);
		target = "addForm";
		return target;
	}

	/**
	 * toDo:保存部门信息记录;
	 * 
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String createBmxx() {
		if(getUserInfo()!=null)
		{
			appsysBmxx.setCjr(getUserInfo().getYhm());
		}
		if (bmxxService.addBmxx(appsysBmxx))
		{
			//添加部门时,对应添加部门权限;
			//xtbmService.changeBmqx(Constant.SYS_XTBM, getUserInfo().getYhbh(), -1, new String[]{appsysBmxx.getBmbh()});
			//sjbmbh = appsysBmxx.getSjbmbh();
			//appsysBmxx = new AppsysBmxx();
			//appsysBmxx.setSjbmbh(sjbmbh);
			this.handleMessage("info", "添加成功,请继续操作!");
			target = "addSuccess";
		}
		else
		{
		   this.handleMessage("info", "添加失败,联系管理员!");
			target = "addFailure";
		}
		sjbmmc = bmxxService.getBmxx(appsysBmxx.getSjbmbh()).getBmmc();
		return target;
	}

	/**
	 * toDo:生成部门信息编辑表单;
	 * 
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String reworkBmxxForm() {
		try {
			appsysBmxx = bmxxService.getBmxx(bmbhs.split(",")[0]);
			sjbmmc = bmxxService.getBmxx(appsysBmxx.getSjbmbh()).getBmmc();			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			this.handleMessage("info", "打开失败，请联系管理员！");
			e.printStackTrace();
		}
		 
		target = "EditForm";
		return target;
	}

	/**
	 * toDo:更新部门信息记录;
	 * 
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String reworkBmxx() {
		sjbmbh = getAppsysBmxx().getSjbmbh();
		if (bmxxService.updateBmxx(getAppsysBmxx()))
		{
			target = "updateSuccess";
			this.handleMessage("info", "修改成功,请继续操作!");
		}
		else
		{
			target = "updateFailure";
			this.handleMessage("info", "修改失败,请重新修改!");
		}
		sjbmmc = bmxxService.getBmxx(sjbmbh).getBmmc();
		return target;
	}

	/**
	 * toDo:删除部门信息记录;
	 * 
	 * @return target;
	 */
	public String removeBmxx() {
		if (bmxxService.deleteBmxx(bmbhs.split(",")))
		{
			//删除部门时,对应删除部门权限;
			//this.xtbmService.deleteBmQxByBmbh(bmbhs.split(","));
			target = "deleteSuccess";
		}
		else
		{
			target = "deleteFailure";
		}
		return target;
	}
	
	/**
	 * toDo:保存部门排序;
	 * @return target;
	 */
	public String orderBmxx()
	{
		if (bmxxService.orderBmxx(bmId,pxh))
		{
			target = "orderSuccess";
		}
		else
		{
			target = "orderFailure";
			this.handleMessage("info", "排序失败,请重新操作!");
		}
		return target;
	}
	/**
	 * toDo:get部门组织结构树集合;
	 * 
	 * @return the treeList
	 */
	public List<AppsysBmxx> getTreeList() {
		return treeList;
	}

	/**
	 * toDo:set部门组织结构树集合;
	 * 
	 * @param treeList
	 *            the treeList to set
	 */
	public void setTreeList(List<AppsysBmxx> treeList) {
		this.treeList = treeList;
	}
	
	/**
	 * toDo:get上级部门编号
	 * 
	 * @return the sjbmbh
	 */
	public String getSjbmbh() {
		return sjbmbh;
	}

	/**
	 * toDo:set上级部门编号
	 * 
	 * @param sjbmbh
	 *            the sjbmbh to set
	 */
	public void setSjbmbh(String sjbmbh) {
		this.sjbmbh = sjbmbh;
	}

	/**
	 * @toDo:get部门信息对象;
	 * @return the appsysBmxx
	 */
	public AppsysBmxx getAppsysBmxx() {
		return appsysBmxx;
	}

	/**
	 * toDo:set部门信息对象;
	 * @param appsysBmxx  the appsysBmxx to set
	 */
	public void setAppsysBmxx(AppsysBmxx appsysBmxx) {
		this.appsysBmxx = appsysBmxx;
	}

	/**
	 * toDo:get判断查询路径;
	 * 
	 * @return the urlFlag
	 */
	public String getUrlFlag() {
		return urlFlag;
	}

	/**
	 * toDo:set判断查询路径;
	 * 
	 * @param urlFlag
	 *            the urlFlag to set
	 */
	public void setUrlFlag(String urlFlag) {
		this.urlFlag = urlFlag;
	}

	/**
	 * toDo:get多个部门编号;
	 * 
	 * @return the bmbhs
	 */
	public String getBmbhs() {
		return bmbhs;
	}

	/**
	 * toDo:set多个部门编号;
	 * 
	 * @param bmbhs
	 *            the bmbhs to set
	 */
	public void setBmbhs(String bmbhs) {
		this.bmbhs = bmbhs;
	}

	/**
	 * toDo:get返回参数;
	 * 
	 * @param target
	 *            the target to set
	 */
	public void setTarget(String target) {
		this.target = target;
	}

	/**
	 * toDo:set返回参数;
	 * 
	 * @return the target
	 */
	public String getTarget() {
		return target;
	}
	/**
	 * toDo:get部门信息集合;
	 * 
	 * @return the bmxxList
	 */
	public List<AppsysBmxx> getBmxxList() {
		return bmxxList;
	}

	/**
	 * toDo:set部门信息集合;
	 * 
	 * @param bmxxList
	 *            the bmxxList to set
	 */
	public void setBmxxList(List<AppsysBmxx> bmxxList) {
		this.bmxxList = bmxxList;
	}

	/**
	 * toDo:get部门信息业务处理
	 * 
	 * @return the bmxxService
	 */
	public BmxxService getBmxxService() {
		return bmxxService;
	}

	/**
	 * toDo:set部门信息业务处理
	 * 
	 * @param bmxxService
	 *            the bmxxService to set
	 */
	public void setBmxxService(BmxxService bmxxService) {
		this.bmxxService = bmxxService;
	}
	/**
	 * @toDo:get部门编号 ;
	 * @return the bmbh
	 */
	public String getBmbh() {
		return bmbh;
	}
	/**
	 * @toDo:set部门编号 ;
	 * @param bmbh the bmbh to set
	 */
	public void setBmbh(String bmbh) {
		this.bmbh = bmbh;
	}
	/**
	 * @return the bmId
	 */
	public String[] getBmId() {
		return bmId;
	}
	/**
	 * @param bmId the bmId to set
	 */
	public void setBmId(String[] bmId) {
		this.bmId = bmId;
	}
	/**
	 * @return the pxh
	 */
	public String[] getPxh() {
		return pxh;
	}
	/**
	 * @param pxh the pxh to set
	 */
	public void setPxh(String[] pxh) {
		this.pxh = pxh;
	}
	/**
	 * @return the sjbmmc
	 */
	public String getSjbmmc() {
		return sjbmmc;
	}
	/**
	 * @param sjbmmc the sjbmmc to set
	 */
	public void setSjbmmc(String sjbmmc) {
		this.sjbmmc = sjbmmc;
	}
	/**
	 * @return the xtbmService
	 */
	public XtbmService getXtbmService() {
		return xtbmService;
	}
	/**
	 * @param xtbmService the xtbmService to set
	 */
	public void setXtbmService(XtbmService xtbmService) {
		this.xtbmService = xtbmService;
	}
}
